#ifndef CSOLAR_NEBULA_H
#define CSOLAR_NEBULA_H

#include <string>
#include <iostream>
#include <fstream>
#include <vector>
#include <time.h>
using namespace std;

#include "../Particle/CParticle.h"
#include "CImg.h"
using namespace cimg_library;

template <typename _PO>
class CSolarNebula {
public:
	typedef _PO		particle_t;
	typedef typename particle_t::value_pattern_t	value_pattern_t;
	typedef typename particle_t::label_t			label_t;
	typedef typename particle_t::gravity_t			gravity_t;
	typedef typename particle_t::velocity_t			velocity_t;
	typedef typename particle_t::pattern_t			pattern_t;
	typedef list<particle_t>						container_t;

public:
	container_t		_nebula;

	CSolarNebula (string _image) {
		CImg<unsigned char> image(_image.c_str());
		image.display();

		for (int i = 0; i < image.width(); i++)
			for (int k = 0; k < image.height(); k++){
				pattern_t _pattern;
				for (int f = 0; f < 3; f++){
					_pattern << image(i,k,f);
				}
				particle_t _particle(_pattern, i, k);
				_nebula.push_back(_particle);
			}

	}

	CSolarNebula (string _filename, int _features, int _total, bool _l =  false){		
		srand (time(NULL));
		ifstream _file (_filename.c_str());
		while (!_file.eof()) {
			pattern_t _pattern;
			value_pattern_t _feature;

			for (int _i = 0; _i  < _features;  _i++){
				_file >> _feature; _pattern << _feature;
			}

			if (_l) {
				label_t	_label = "";
				_file >> _label; _pattern << _label;
			}
//			int x , y ;
//			_file >> x >> y;
//			particle_t _particle(_pattern, x, y);
			particle_t _particle(_pattern, rand()%50, rand()%50);
//			particle_t _particle(_pattern, 100, 100);
			_nebula.push_back(_particle);
		} 
		_file.close();
	}

	template <typename __PO>
	friend ostream& operator << (ostream& out, CSolarNebula<__PO>& _s){
//		out << _s._nebula.size() << endl;
		container_t::iterator it = _s._nebula.begin();
		for (; it != _s._nebula.end(); it++)
			out << *it << endl;
		return out;
	}

	~CSolarNebula(){
	}

};


#endif 